<template>
	<view class="container">
		<view class="user-section">
			<!-- <view class="rech_recode" @click="navToUrl('/pages/wallet/cashlog')">提现记录</view> -->
			<view class="vip-card-box" style="margin-top:3vw;">
				<view class="main_top">
					<view class="main_con">
						<view class="money">{{ money}}</view>
						<view class="text" >可提余额(元)</view>
					</view>
				</view>
			</view>
		</view>
		
		<view class="tab-bar">
			<view class="tab_item">
				<view class="cu-form-group margin-lr-lg border-b-line padding-0">
					<view class="title">提现金额</view>
				</view>
				<view class="cu-form-group margin-lr-lg border-b-line padding-0" style="border-top:none;border-bottom:0.5px solid #eee;">
					<text class="text-price text-xxlx"></text>
					<input class="text-xxlx" data-key="coin" number focus placeholder="0.00" v-model="coin" @input="inputCoin" style="color:#fff;">
				</view>
				<view class="cu-form-group margin-lr-lg border-b-line padding-0">
					<text class="text-sm">手续费: </text>
					<text class="text-sm text-price">{{fee}}</text>
				</view>					
				<view class="bank xntx_cont" @click="navToBank()">
					<view class="cu-avatar round lg xntx" ></view>
					<view class="bank_main">
						<view class="bank_tit">111{{ bankData.bank }} </view>
						<view class="bank_acount">12121{{ bankData.account }}</view>
					</view>
					<view class="cuIcon-right"></view>
				</view>
			</view>
		</view>
		
		<view class="cash">
			<button :disabled="enableCash" class="cu-btn" type="button" @click="cashOut()">确认提现</button>
		</view>
	<view>
	    <payKeyboard v-if="showKeyBoard" title="安全键盘" @success="finish" @close="close"></payKeyboard>
	</view>	
		<view class="footer-info">
				<view>提现规则如下：</view>
				<view>提现时间：</view>
				<view>{{this.text1}}</view>
				<view>最低提现金额：</view>
				<view>{{this.text2}}</view>
				<view>提现处理到账时间：</view>
				<view>{{this.text3}}</view>
				<view>单日提现次数：{{this.text4}}</view>
				<!-- <view>{{this.text4}}</view> -->
			</view>	
		
	</view>
</view>	
</template>

<script>
	import payKeyboard from '@/components/mi-payKeyboard/mi-payKeyboard.vue';
	export default {
		components: {
			payKeyboard
		},
		data() {
			return {
				loaded: !1,
				loading: !1,
				showKeyBoard: false,
				enableScroll: !0,
				loadMoreStatus: 2,
				showLoadMoreStatus: !1,
				coin: "",
				money: "0.00",
				mincash: "0",
				maxcash: "0",
				allowable:null,
				// cashfreequota: "2000.00",
				feeRate: 0.02, // 手续费率
				fee: 0, // 手续费
				casetimes: "1",
				enableCash: !0,
				showCashPanel: !1,
				// cashFeeCoin: 0,
				passInputTips: "",
				bankData: {},
				bank_id:'0',
				begintime:'',
				endtime:'',
				text1:'',
				text2:'',
				text3:'',
				text4:'',
			}
		},
		onNavigationBarButtonTap(val) {
			uni.navigateTo({
				url: '/pages/wallet/cashlog',
			});	
		},
		onLoad: function (option) {
			this.helper.checkLogin();
			this.loadData();
		},
		onShow:function(e){
			let pages = getCurrentPages();
			let currPage = pages[pages.length-1];
			if (currPage.$vm.bank_id){
				this.bank_id = currPage.$vm.bank_id;
				this.loadData();
			}
		},
		methods: {
			// 点击[取消] 关闭输入框 的回调
			close(){
				this.showKeyBoard = false,
				this.enableCash = !1;
			},				
			loadData:function(){
				//获取基础参数
				// uni.showLoading({
				// 	title:"数据加载中",
				// 	mask:true
				// })
				var info = uni.getStorageSync("userinfo");
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(['bank_id='+this.bank_id,'token='+info.token,'timestamp='+timestamp]);
				this.helper.req({
					api:"cashoutBefore",
					timestamp:timestamp,
					data:{bank_id:this.bank_id,token:info.token},
					header:{sign:sign},
					method:'GET',
				}).then(res=>{
					uni.hideLoading();
					switch (res.data.data.status){
						case 'noauth':
							uni.showModal({
								title: "提示",
								content: '帐户未实名，现在实名？',
								showCancel:false,
								confirmText: "现在实名",
								success:function(res){
									if(res.confirm){
										uni.navigateTo({
											url: "/pages/user/certification"
										})
									}
								}
							})
							break;
						case 'nopaypwd':
							  uni.showModal({
								title: "提示",
								content: '未设置支付密码',
								showCancel:false,
								confirmText: "现在设置",
								success:function(res){
									if(res.confirm){
										uni.navigateTo({
											url: "/pages/user/repasswd?type=pay"
										})
									}
								}
							})   
							break;
						case 'nobank':
							uni.showModal({
								title: "提示",
								content: '未添加银行卡',
								showCancel:false,
								confirmText: "现在添加",
								success:function(res){
									if(res.confirm){
										uni.navigateTo({
											url: "/pages/bank/manage?type=add"
										})
									}
								}
							})
							break;
						case "success":
							this.bankData = res.data.data.bank,
							this.money = res.data.data.money,
							this.mincash = res.data.data.mincash,
							this.maxcash = res.data.data.maxcash,
							// this.cashfreequota = res.data.data.cashfreequota,
							this.feeRate = res.data.data.fee /100,
							this.begintime = res.data.data.begintime,
							this.endtime = res.data.data.endtime,
							this.text1 = res.data.data.text1,
							this.text2 = res.data.data.text2,
							this.text3 = res.data.data.text3,
							this.text4 = res.data.data.text4,
							this.showCashPanel = !0,
							this.loaded = !0;
							break;
						default:
						
							break;
					}
				})
			},
			inputCoin: function(e) {
				this.enableCash = !(parseFloat(e.detail.value) > 0);
				if (!isNaN(e.detail.value)) {
					this.fee = (e.detail.value * this.feeRate).toFixed(2); // 计算手续费
				} else {
					this.fee = 0; // 输入不合法时手续费为 0
				}
			},
			cashOut: function() {
				this.passInputTips = "金额：" + this.coin;
				this.enableCash = !0;
				this.showKeyBoard = true;
			},
			navToBank: function() {
				uni.navigateTo({
					url: "/pages/bank/index?source=1"
				})
			},
			finish: function(e) {
				
				if(e.length < 6){
					uni.showToast({
						title:"密码无效",
						icon:"none"
					})
					this.enableCash = !1
					return;
				}
				if(this.coin == '' || parseFloat(this.coin) <= 0){
					uni.showToast({
						title:"请输入转出金额",
						icon:"none"
					})
					this.enableCash = !1
					return;
				}
				if(parseFloat(this.coin) < this.mincash){
					uni.showToast({
						title:"提现金额不能小于" + this.mincash,
						icon:"none"
					})
					this.enableCash = !1
					return;
				}
				if(parseFloat(this.coin) > this.maxcash){
					uni.showToast({
						title:"当前会员等级最高单笔提现额度为" + this.maxcash+"元",
						icon:"none",
						duration: 5000 // 设置消息显示的时间为 2000 毫秒
					})
					this.enableCash = !1
					return;
				}
				this.enableCash = !0;
				this.showKeyBoard = false;
				var info = uni.getStorageSync("userinfo");
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(['pwd='+e,'bank_id='+this.bankData.id,'coin='+this.coin,'timestamp='+timestamp,'token='+info.token]);
				this.helper.req({
					api:"doCashout",
					timestamp:timestamp,
					data:{pwd:e,bank_id: this.bankData.id,coin:this.coin,token:info.token},
					header:{sign:sign},
					method:'POST',
				}).then(res=>{

					let orderid = res.data.data.orderid;
					uni.redirectTo({
						url: "/pages/wallet/cashout_success?orderid="+orderid
					})
				})
				this.coin = "";
			},
			hideModal: function() {
				this.showKeyBoard = false;
				this.enableCash = !1
			},
		}
	}
</script>
<style lang="scss">
page {

		background-color: #ddeafd;
		height:100%;
}
body.pages-bank-manage uni-page-body{
	background-image: none;
}
.rech_recode{
	width: 100%;
	height: 10vw;
	padding: 4vw 4vw 0;
	color:#fff;
	font-size: 14px;
	text-align: right;
}

	.tab-bar {
		margin: 0 40rpx;
		height: 80vw;
		 
		position: relative; 
		background: #fff;
		border-radius: 20rpx;
		.tab_item{
			color:#353535;
			 
			width: 100%;
			height: 70vw;
			
			.cu-form-group{
				background-color:transparent;
			}
			
			.bank{
				display: flex;
				align-items: center;
				padding: 4vw;
				image{
					width: 16vw;
					height: 16vw;
					margin: 2vw ;
					border-radius: 9vw;
				}
				.xntx{
					background: #003665;
				}
				.bank_main{
					width: 56vw;
					padding: 4vw 2vw;
					.bank_tit{
						font-size: 16px;
						line-height: 6vw;
					}
					.bank_acount{
						font-size: 14px;
						line-height: 6vw;
					}
				}
				.cuIcon-right{
					width: 10vw;
					font-size: 30px;
					line-height: 20vw;
					text-align: right;
				}
			}
		}
	}
	
	.cash{
		width: 100%;
		height: 20vw;
		margin-top: 10vw;
		
		.cu-btn{
			width: 70vw;
			height: 10vw;
			line-height: 10vw;
			text-align: center;
			color: #fff;
			font-size: 16px;
			border-radius: 5vw;
			margin-left: 15vw;
			background: linear-gradient( 180deg, #50A7FF 0%, #3267FF 100%);
		}
	}

	.vip-card-box {
		height: 16vh;
		border-radius: 16upx;
		overflow: hidden;
		position: relative;
		margin: 0 20upx 0;
		background-image: url('');
		background-repeat: no-repeat;
		background-size: 100%;
		.money{
			color: #4188ff;
			text-align: center;
			font-size: 50rpx;
			font-weight: bold;
			padding-top: 65rpx;
		}
		.text{
			text-align: center;
			color: #353535;
			padding-top: 10rpx;
		}
	}
	input.text-xxlx{
		font-size: 50upx;
		padding-left: 10upx;
	}
	.screen-swiper{
		min-height: 300upx;
	}
	.footer-info {
		background: #fff;
		color: #353535;
		border-radius: 10px;
		margin-bottom: .59rem;
		padding: 4vw 4vw;
		margin: 0 40rpx;
	}	
</style>